package com.study.d1_arrays;

import java.util.Arrays;
import java.util.Comparator;

public class Test2 {
    public static void main(String[] args) {
        //给存储对象的数组进行排序
        Student[] students = new Student[4];
        students[0]=new Student("一帆风顺",175,'男',20);
        students[1]=new Student("二话不说",165,'男',130);
        students[2]=new Student("三心二意",170,'女',220);
        students[3]=new Student("四面八方",185,'女',10);
//        Arrays.sort(students);
//        System.out.println(Arrays.toString(students));
        //自定义比较规则1：让对象所在的类实现比较规则Comparable，重写compareTo方法，来指定比较规则
//        Arrays.sort(students);
//        System.out.println(Arrays.toString(students));
        //自定义比较规则2：sort存在重载的方法，支持自带Comparator比较器对象来直接指定比较规则(优先)
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge()-o1.getAge();
            }
        });
        System.out.println(Arrays.toString(students));
    }
}
